package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.redis.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * redis缓存数据持久化定时任务
 */
@Component //交给spring容器管理
public class RedisDataPersistenceJob {
    @Autowired
    private IStrategyStatisVORedisService statisVORedisService;
    @Autowired
    private IStrategyService strategyService;
    //cron:表达式,任务计划
    //定时任务标签
    @Scheduled(cron = "0/5 * * * * ?")
    public void dowork(){
        //开始
        System.out.println("--------redis缓存数据持久化start-------------");
        //从redis中获取缓存数据
        List<StrategyStatisVO> vos =  statisVORedisService.queryStatisVOS();
        //遍历所有的vo
        for (StrategyStatisVO vo : vos) {
            //更新到数据库
            strategyService.updateStatisVo(vo);
        }
        //结束
        System.out.println("--------redis缓存数据持久化end-------------");
    }
}
